<?php
class HeadSearchWidget extends CWidget
{
    public $keyword = '';
    public function init()
    {
        parent::init();
    }
    public function run()
    {
        $attr['status'] =1;
        $attr['page'] =1;
        $attr['page_size'] =5;
        $hot_search = SearchLog::model()->ListByAttr($attr); 
        $logo_2 = Config::model()->get('logo_2');//logo 2
        $logo = Config::model()->get('logo');//logo
        $cart_count = 0;
        $cart_goods_count = 0;
        if (!Yii::app()->user->isGuest) {
            $filter['user_id'] = Yii::app()->user->getId();
            $data = Cart::model()->CountByAttr($filter);
            if (!empty($data) && isset($data['goods_count'])) {
                $cart_goods_count = $data['goods_count'];//只计算商品的种类数量
                $cart_count =  $data['total_count'];//包含商品的 购物车里的数量
            }
        }
        $keyword = $this->keyword;
        $this->render('headsearch',compact('hot_search','logo_2','logo','cart_count','cart_goods_count','keyword'));
    }
}
?>
